<template>
  <a-card>
    <div class="provide">
      <div class="img">
        <img :src="productDetail.image" />
        <a-rate v-model="isCollect" :count='1' @change="addCollect" />
        收藏服务
      </div>
      <div class="info">
        <h3>{{ productDetail.name }}</h3>
        <span>{{ productDetail.describe }}</span>
<!--        <div v-if="productDetail.price != 0" class="price">服务价格：<p>￥<span>{{ productDetail.price }}</span></p></div>-->
        <div class="product_no">业务类型：<a>{{productDetail.name}}</a></div>
        <div class="btn">
          <a-button type="danger" size="large" @click="onSwt">立即咨询</a-button>
<!--          <a-button v-if="productDetail.price != 0" type="danger" size="large" @click="addCart" ghost>加入购物车</a-button>-->
        </div>
        <div class="intro">服务承诺&nbsp;&nbsp;&nbsp;<span>专家1V1</span>&nbsp;&nbsp;&nbsp;<span>价格透明</span>&nbsp;&nbsp;&nbsp;<span>规避风险</span></div>
      </div>
      <div class="servicer">
        <h4>— 卓一知产资深顾问 —</h4>
        <div class="avator">
          <img src="@/assets/images/img_avator.jpg" />
        </div>
        <a-button class="consult" @click="onSwt">在线咨询</a-button>
        <div class="tel">
          <p>在线时间：00:00-24:00<br />联系电话：400-9010-891</p>
        </div>
      </div>
    </div>
    <div class="detail-content">
      <h3 class="my-ser">服务介绍</h3>
      <div class="content" v-html="productDetail.content"></div>
    </div>
  </a-card>
</template>

<script>
import { getProductDetail } from '@/api/product'
import { addCart } from '@/api/cart'
import { addCollect } from '@/api/collect'
import apis from '@/api'

export default {
  name: 'ProductDetail',
  data () {
    return {
      productDetail: {},
      isCollect: 0
    }
  },
  created () {
    this.getDetail(this.$route.params.id)
  },
  methods: {
    getDetail (id) {
      getProductDetail(id).then(res => {
        this.productDetail = res.result.data
        this.isCollect = res.result.is_collect
      })
    },
    addCart () {
      const app = this
      const data = {}
      data['gid'] = app.$route.params.id
      addCart(data).then(res => {
        if (res.status === 0) {
          app.$message.success('添加购物车成功')
          app.getDetail(app.$route.params.id)
          app.$router.go(0)
        } else {
          app.$warning({
            title: res.msg
          })
          app.$router.push({ name: 'Login' })
        }
      })
    },
    onSwt () {
      window.open(apis.Swt)
    },
    addCollect () {
      const app = this
      addCollect(app.$route.params.id).then(res => {
        if (res.status === 0) {
          app.$message.success('操作成功')
          app.getDetail(app.$route.params.id)
        } else {
          app.$router.push({ name: 'Login', query: { redirect: this.$route.path } })
        }
      })
    }
  }
}
</script>

<style scoped>
h3, p, a, li, ul, div, span {
  margin: 0;
  padding: 0;
  font-weight: 500;
}

.provide {
  width: 1190px;
  margin: 0 auto;
  background-color: #FFFFFF;
  padding: 27px 0;
  display: flex;
  justify-content: space-between;
}

.provide .img {
  width: 300px;
  height: 300px;
}

.provide .img img {
  width: 100%;
}

.provide .info {
  width: 480px;
  margin-left: 5px;
  font-size: 14px;
  color: #999999;
}

.provide .info h3 {
  font-size: 22px;
  color: #333333;
  font-weight: 500;
}

.provide .info .price {
  background-color: #e6e6e6;
  height: 65px;
  display: flex;
  align-items: center;
  margin-top: 20px;
  padding-left: 10px;
}

.provide .info .price p {
  color: #e83632;
  font-size: 18px;
}

.provide .info .price p span {
  font-size: 24px;
}

.provide .info .price a {
  color: #e83632;
  text-decoration: underline;
  margin-left: 20px;
  cursor: pointer;
}

.provide .info .product_no {
  display: flex;
  align-items: center;
  margin-top: 30px;
  margin-left: 10px;
}

.provide .info .product_no a {
  font-size: 12px;
  color: #d93c30;
  border: solid 1px #d93c30;
  position: relative;
  padding: 0 15px;
  line-height: 30px;
}

.provide .info .product_no a:before {
  position: absolute;
  content: '';
  right: 0;
  bottom: 0;
  width: 0;
  height: 0;
  border-bottom: 6px solid #d93c30;
  border-left: 6px solid transparent;
}

.provide .info .btn {
  display: flex;
  align-items: center;
  color: #666666;
  margin-top: 30px;
}

/deep/ .provide .info .btn button {
  width: 184px;
  margin-right: 10px;
}

.provide .info .intro {
  font-size: 12px;
  display: flex;
  align-items: center;
  margin-top: 20px;
}

.provide .info .intro span {
  color: #666666;
}

.provide .servicer {
  width: 240px;
  height: 337px;
  text-align: center;
  border: solid 1px #ffb5a1;
  box-shadow: 0 0 10px 1px rgba(255, 181, 181, 0.3);
}

.provide .servicer h4 {
  font-size: 16px;
  color: #999999;
  margin: 27px 0 25px;
}

.provide .servicer .consult {
  font-size: 16px;
  color: #ffffff;
  display: inline-block;
  width: 123px;
  height: 32px;
  line-height: 32px;
  cursor: pointer;
  background: linear-gradient(to right, #ff9376, #ff734e);
  margin-top: 25px;
}

.provide .servicer .tel {
  border-top: dashed 1px #d6d6d6;
  margin-top: 16px;
}

.provide .servicer .tel p {
  font-size: 12px;
  color: #999999;
  display: inline-block;
  text-align: right;
  margin-top: 8px;
  line-height: 23px;
}

.detail-content {
  width: 1190px;
  margin: 0 auto;
  overflow: hidden;
}

.detail-content .my-ser {
  padding-left: 16px;
  background-color: #f0f0f0;
  font-size: 14px;
  color: #333;
  overflow: hidden;
  line-height: 40px;
  height: 40px;
}

.detail-content p {
  margin: 0;
}

.detail-content img {
  display: block;
  width: 100%;
}
</style>
